home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / guis / iedit / developer / loaders / gtb / funcs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-11  |  23.7 KB  |  853 lines

  1. /*
  2.     GTB.loader
  3.     Copyright ©1996 Simone Tellini
  4.          All Rights Reserved
  5.  
  6.     Take this as an example... ;-)
  7. */
  8.  
  9. /// Include
  10. #define INTUI_V36_NAMES_ONLY
  11. #define CATCOMP_NUMBERS
  12.  
  13. #include <exec/types.h>                 // exec
  14. #include <exec/lists.h>
  15. #include <exec/memory.h>
  16. #include <exec/nodes.h>
  17. #include <exec/execbase.h>
  18. #include <dos/dos.h>                    // dos
  19. #include <intuition/intuition.h>        // intuition
  20. #include <intuition/gadgetclass.h>
  21. #include <libraries/gadtools.h>         // libraries
  22. #include <gadtoolsbox/forms.h>          // gadtoolsbox
  23. #include <gadtoolsbox/gui.h>
  24. #include <clib/exec_protos.h>           // protos
  25. #include <clib/dos_protos.h>
  26. #include <clib/gtx_protos.h>
  27. #include <clib/nofrag_protos.h>
  28. #include <clib/utility_protos.h>
  29. #include <pragmas/exec_pragmas.h>
  30. #include <pragmas/dos_pragmas.h>
  31. #include <pragmas/gtx_pragmas.h>
  32. #include <pragmas/nofrag_pragmas.h>
  33. #include <pragmas/graphics_pragmas.h>
  34. #include <pragmas/utility_pragmas.h>
  35.  
  36. #include <stdarg.h>
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <ctype.h>
  41.  
  42. #include "DEV_IE:Loaders/defs.h"
  43. ///
  44. /// Prototypes
  45. static BOOL                 ConvertMenus( struct IE_Data *, struct WindowInfo *, struct ExtMenuList * );
  46. static BOOL                 ConvertIText( struct IE_Data *, struct WindowInfo *, struct IntuiText * );
  47. static BOOL                 ConvertBox( struct IE_Data *, struct WindowInfo *, struct BevelBox * );
  48. static struct WindowInfo   *ConvertWin( struct IE_Data *, struct ProjectWindow * );
  49. static BOOL                 ConvertGad( struct IE_Data *, struct WindowInfo *, struct ExtNewGadget * );
  50. static ULONG                ConvertScr( struct IE_Data *, GUIDATA * );
  51. static ULONG                ConvertColors( struct IE_Data *, UWORD, GUIDATA * );
  52.  
  53. extern struct GTXBase *GTXBase;
  54. extern struct Library *GfxBase;
  55. ///
  56. /// Data
  57. static const UBYTE  Bar_txt[]       = "---------------------------";
  58.  
  59. static const UWORD stringjusts[] = {
  60.     GACT_STRINGLEFT, GACT_STRINGRIGHT, GACT_STRINGCENTER
  61. };
  62.  
  63. static const ULONG gadget_flags[] = { 1, 2, 4, 8, 16, 0 };
  64. ///
  65.  
  66.  
  67. // Conversion routines
  68. /// Windows
  69. struct WindowInfo *ConvertWin( struct IE_Data *IE, struct ProjectWindow *from )
  70. {
  71.     struct WindowInfo   *wnd;
  72.     struct Screen       *scr;
  73.  
  74.     if( wnd = ( *IE->Functions->AllocObject )( IE_WINDOW )) {
  75.  
  76.     NewList( &wnd->wi_Gadgets );
  77.     NewList( &wnd->wi_Menus   );
  78.     NewList( &wnd->wi_Boxes   );
  79.     NewList( &wnd->wi_Images  );
  80.     NewList( &wnd->wi_ITexts  );
  81.  
  82.     AddTail( (struct List *)&IE->win_list, (struct Node *)wnd );
  83.  
  84.     IE->num_win += 1;
  85.  
  86.     wnd->wi_name = wnd->wi_Titolo;
  87.  
  88.     wnd->wi_Flags           = from->pw_WindowFlags;
  89.     wnd->wi_IDCMP           = from->pw_IDCMP;
  90.     wnd->wi_InnerWidth      = from->pw_InnerWidth;
  91.     wnd->wi_InnerHeight     = from->pw_InnerHeight;
  92.     wnd->wi_MouseQueue      = from->pw_MouseQueue;
  93.     wnd->wi_RptQueue        = from->pw_RptQueue;
  94.  
  95.     if( from->pw_TagFlags & WDF_INNERWIDTH )
  96.         wnd->wi_flags1 |= W_USA_INNER_W;
  97.  
  98.     if( from->pw_TagFlags & WDF_INNERHEIGHT )
  99.         wnd->wi_flags1 |= W_USA_INNER_H;
  100.  
  101.     if( from->pw_TagFlags & WDF_MOUSEQUEUE )
  102.         wnd->wi_Tags |= W_MOUSEQUEUE;
  103.  
  104.     if( from->pw_TagFlags & WDF_RPTQUEUE )
  105.         wnd->wi_Tags |= W_RPTQUEUE;
  106.  
  107.     if( from->pw_TagFlags & WDF_AUTOADJUST )
  108.         wnd->wi_Tags |= W_AUTOADJUST;
  109.  
  110.     if( from->pw_TagFlags & WDF_FALLBACK )
  111.         wnd->wi_Tags |= W_FALLBACK;
  112.  
  113.     if( from->pw_TagFlags & WDF_ZOOM ) {
  114.         wnd->wi_Tags |= W_ZOOM;
  115.         wnd->wi_ZLeft = wnd->wi_ZTop = -1;    // don't move
  116.         wnd->wi_ZWidth = wnd->wi_Width;
  117.         wnd->wi_ZHeight = IE->ScreenData->YOffset + 1;
  118.     }
  119.  
  120.     scr = IE->ScreenData->Screen;
  121.  
  122.     wnd->wi_Width    = wnd->wi_InnerWidth + scr->WBorRight + scr->WBorLeft;
  123.     wnd->wi_Height   = wnd->wi_InnerHeight + IE->ScreenData->YOffset + 1 + scr->WBorBottom;
  124.     wnd->wi_MaxWidth = wnd->wi_MaxHeight = -1;
  125.  
  126.     strcpy( wnd->wi_Titolo,         from->pw_WindowTitle );
  127.     strcpy( wnd->wi_TitoloSchermo,  from->pw_ScreenTitle );
  128.     strcpy( wnd->wi_Label,          from->pw_Name        );
  129.  
  130.     #ifdef DEBUG
  131.     Printf( "WINDOW: %s\n", wnd->wi_Titolo );
  132.     #endif
  133.  
  134.     struct ExtNewGadget *gad;
  135.     for( gad = from->pw_Gadgets.gl_First; gad->en_Next; gad = gad->en_Next )
  136.         if(!( ConvertGad( IE, wnd, gad )))
  137.         return( NULL );
  138.     #ifdef DEBUG
  139.     Printf( "ConvertGad() OK\n" );
  140.     #endif
  141.  
  142.     struct BevelBox     *box;
  143.     for( box = from->pw_Boxes.bl_First; box->bb_Next; box = box->bb_Next )
  144.         if(!( ConvertBox( IE, wnd, box )))
  145.         return( NULL );
  146.     #ifdef DEBUG
  147.     Printf( "ConvertBox() OK\n" );
  148.     #endif
  149.  
  150.     struct IntuiText    *txt;
  151.     txt = from->pw_WindowText;
  152.     while( txt ) {
  153.         if(!( ConvertIText( IE, wnd, txt )))
  154.         return( NULL );
  155.         txt = txt->NextText;
  156.     }
  157.     #ifdef DEBUG
  158.     Printf( "ConvertIText() OK\n" );
  159.     #endif
  160.  
  161.     if(!( ConvertMenus( IE, wnd, &from->pw_Menus )))
  162.         return( NULL );
  163.     #ifdef DEBUG
  164.     Printf( "ConvertMenus() OK\n" );
  165.     #endif
  166.  
  167.     }
  168.  
  169.     return( wnd );
  170. }
  171. ///
  172. /// IntuiTexts
  173. BOOL ConvertIText( struct IE_Data *IE, struct WindowInfo *wnd, struct IntuiText *from )
  174. {
  175.     struct ITextNode   *itn, *itn2;
  176. /*    struct TxtAttrNode *fnt; */
  177.  
  178.     if( itn = ( *IE->Functions->AllocObject )( IE_INTUITEXT )) {
  179.  
  180.     AddTail(( struct List * )&wnd->wi_ITexts, ( struct Node * )itn );
  181.     itn->itn_Node.ln_Name = itn->itn_IText = itn->itn_Text;
  182.  
  183.     wnd->wi_NumTexts += 1;
  184.  
  185.     itn2 = itn->itn_Node.ln_Pred;
  186.  
  187.     if( itn2->itn_Node.ln_Pred )
  188.         itn2->itn_NextText = &itn->itn_FrontPen;
  189.  
  190.     strcpy( itn->itn_Text, from->IText );
  191.  
  192.     itn->itn_FrontPen = from->FrontPen;
  193.     itn->itn_BackPen  = from->BackPen;
  194.     itn->itn_DrawMode = from->DrawMode;
  195.     itn->itn_LeftEdge = from->LeftEdge;
  196.     itn->itn_TopEdge  = from->TopEdge;
  197.  
  198.     itn->itn_Node.ln_Type |= IT_SCRFONT;
  199.  
  200. /*
  201.     This part causes some Enforcer hits, probably because GTB puts
  202.     some strange data in the ITextFont field of IntuiText...
  203.     Anyway, if you manage to fix this... ;-)
  204.  
  205.     if( from->ITextFont ) {
  206.         if( fnt = ( *IE->Functions->AddFont )( from->ITextFont )) {
  207.  
  208.         if(!( fnt->txa_Ptr ))
  209.             IE->flags |= NODISKFONT;
  210.         else
  211.             itn->itn_Node.ln_Type &= ~IT_SCRFONT;
  212.  
  213.         itn->itn_FontCopy = &fnt->txa_FontName;
  214.         } else
  215.         IE->flags |= NODISKFONT;
  216.  
  217.         if(!( itn->itn_Node.ln_Type & IT_SCRFONT ))
  218.         itn->itn_ITextFont = itn->itn_FontCopy;
  219.     }  */
  220.  
  221.     } else
  222.     return( FALSE );
  223.  
  224.     return( TRUE );
  225. }
  226. ///
  227. /// Bevel Box
  228. BOOL ConvertBox( struct IE_Data *IE, struct WindowInfo *wnd, struct BevelBox *from )
  229. {
  230.     struct BevelBoxNode    *box;
  231.  
  232.     if( box = ( *IE->Functions->AllocObject )( IE_BEVELBOX )) {
  233.  
  234.     AddTail( (struct List *)&wnd->wi_Boxes, (struct Node *)box );
  235.  
  236.     wnd->wi_NumBoxes += 1;
  237.  
  238.     box->bb_VITag       = GT_VisualInfo;
  239.     box->bb_TTag        = GTBB_FrameType;
  240.     box->bb_RTag        = TAG_IGNORE;
  241.  
  242.     box->bb_Left        = from->bb_Left;
  243.     box->bb_Top         = from->bb_Top;
  244.     box->bb_Width       = from->bb_Width;
  245.     box->bb_Height      = from->bb_Height;
  246.  
  247.     if( from->bb_Flags & BBF_RECESSED ) {
  248.         box->bb_RTag = GTBB_Recessed;
  249.         box->bb_Recessed = TRUE;
  250.     }
  251.  
  252.     box->bb_FrameType = ( from->bb_Flags & BBF_DROPBOX ) ? BBFT_ICONDROPBOX : BBFT_BUTTON;
  253.  
  254.     } else {
  255.     return( FALSE );
  256.     }
  257.  
  258.     return( TRUE );
  259. }
  260. ///
  261. /// Gadgets
  262. BOOL ConvertGad( struct IE_Data *IE, struct WindowInfo *wnd, struct ExtNewGadget *from )
  263. {
  264.     struct GadgetInfo      *gad;
  265.     struct GadgetScelta    *gs;
  266.     UBYTE                 **labels;
  267.     UWORD                   cnt, cnt2;
  268.     UBYTE                  *ptr, ch;
  269.  
  270.     if(( from->en_Kind >= BOOLEAN ) || ( from->en_Kind == GENERIC_KIND ))
  271.     return( TRUE );
  272.  
  273.     if(!( gad = ( *IE->Functions->AllocObject )( IE_GADGET )))
  274.     return( FALSE );
  275.  
  276.     AddTail( (struct List *)&wnd->wi_Gadgets, (struct Node *)gad );
  277.  
  278.     gad->g_UserData     = gad;
  279.     gad->g_VisualInfo   = IE->ScreenData->Visual;
  280.     gad->g_GadgetText   = gad->g_Titolo;
  281.  
  282.     NewList( &gad->g_Scelte );
  283.  
  284.     gad->g_Kind = from->en_Kind;
  285.  
  286.     // NewGadget structure
  287.     gad->g_Left     = from->en_NewGadget.ng_LeftEdge;
  288.     gad->g_Top      = from->en_NewGadget.ng_TopEdge - IE->ScreenData->YOffset;
  289.     gad->g_Width    = from->en_NewGadget.ng_Width;
  290.     gad->g_Height   = from->en_NewGadget.ng_Height;
  291.     gad->g_Flags    = from->en_NewGadget.ng_Flags;
  292.  
  293.     // strings
  294.     strcpy( gad->g_Titolo, from->en_GadgetText );
  295.     strcpy( gad->g_Label, from->en_GadgetLabel );
  296.  
  297.     #ifdef DEBUG
  298.     Printf( "    - Gadget: %s  \t  Kind: %ld\n", gad->g_Titolo, gad->g_Kind );
  299.     #endif
  300.  
  301.     // let's alloc some space for its string
  302.     if(( gad->g_Kind == STRING_KIND ) || ( gad->g_Kind == TEXT_KIND )) {
  303.     if(!( gad->g_ExtraMem = AllocVec( 120, MEMF_CLEAR ))) {
  304.         Remove(( struct Node *)gad );
  305.         ( *IE->Functions->FreeObject )( gad, IE_GADGET );
  306.         return( FALSE );
  307.     }
  308.     }
  309.  
  310.     // Now we translate the tags. Note my more compact way of storing
  311.     // them *;D
  312.  
  313.     switch( from->en_Kind ) {
  314.  
  315.     case CHECKBOX_KIND:
  316.         if( GTX_TagInArray( GTCB_Checked, from->en_Tags ))
  317.         gad->g_Tags |= 2;
  318.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  319.         gad->g_Tags |= 2;
  320.         break;
  321.  
  322.     case CYCLE_KIND:
  323.  
  324.         labels = (UBYTE **)GetTagData( GTCY_Labels, NULL, from->en_Tags );
  325.  
  326.         // count the labels
  327.         cnt = 0;
  328.         while( labels[ cnt ] )
  329.         cnt++;
  330.  
  331.         gad->g_NumScelte = cnt;
  332.  
  333.         for( cnt2 = 0; cnt2 < gad->g_NumScelte; cnt2++ ) {
  334.         if(!( gs = ( *IE->Functions->AllocObject )( IE_ITEM )))
  335.             return( FALSE );
  336.  
  337.         AddTail( (struct List *)&gad->g_Scelte, (struct Node *)gs );
  338.         gs->gs_Node.ln_Name = gs->gs_Testo;
  339.  
  340.         strcpy( gs->gs_Testo, *labels++ );
  341.         }
  342.  
  343.         if( GTX_TagInArray( GTCY_Active, from->en_Tags ))
  344.         ((struct CK)( gad->g_Data )).Act = GetTagData( GTCY_Active, NULL, from->en_Tags );
  345.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  346.         gad->g_Tags |= 2;
  347.         break;
  348.  
  349.     case    INTEGER_KIND:
  350.         if ( GTX_TagInArray( GA_TabCycle, from->en_Tags ))
  351.         gad->g_Tags |= 8;
  352.         if ( GTX_TagInArray( STRINGA_ExitHelp, from->en_Tags ))
  353.         gad->g_Tags |= 0x10;
  354.  
  355.         ((struct IK)( gad->g_Data )).Num = GetTagData( GTIN_Number, 0, from->en_Tags );
  356.  
  357.         ((struct IK)( gad->g_Data )).MaxC = GetTagData( GTIN_MaxChars, 10, from->en_Tags );
  358.  
  359.         if ( cnt = GetTagData( STRINGA_Justification, 0l, from->en_Tags )) {
  360.         cnt2 = 0;
  361.         while( stringjusts[ cnt2 ] != cnt )
  362.             cnt2++;
  363.         ((struct IK)( gad->g_Data )).Just = cnt2;
  364.         }
  365.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  366.         gad->g_Tags |= 2;
  367.         break;
  368.  
  369.     case    LISTVIEW_KIND:
  370.         if (GTX_TagInArray( GTLV_ShowSelected, from->en_Tags ))
  371.         gad->g_Tags |= 8;
  372.         if ( GTX_TagInArray( GTLV_ScrollWidth, from->en_Tags ))
  373.         ((struct LK)( gad->g_Data)).ScW = GetTagData( GTLV_ScrollWidth, 0, from->en_Tags );
  374.         else
  375.         ((struct LK)(gad->g_Data)).ScW = 16;
  376.         if ( GTX_TagInArray( GTLV_ReadOnly, from->en_Tags ))
  377.         gad->g_Tags |= 4;
  378.         if ( GTX_TagInArray( LAYOUTA_Spacing, from->en_Tags ))
  379.         ((struct LK)( gad->g_Data)).Spc = GetTagData( LAYOUTA_Spacing, 0, from->en_Tags );
  380.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  381.         gad->g_Tags |= 2;
  382.  
  383.         if( GTX_TagInArray( GTLV_Labels, from->en_Tags )) {
  384.         labels = (UBYTE **)GetTagData( GTLV_Labels, NULL, from->en_Tags );
  385.  
  386.         // count the labels
  387.         cnt = 0;
  388.         while( labels[ cnt ] )
  389.             cnt++;
  390.  
  391.         gad->g_NumScelte = cnt;
  392.  
  393.         for( cnt2 = 0; cnt2 < gad->g_NumScelte; cnt2++ ) {
  394.             if(!( gs = ( *IE->Functions->AllocObject )( IE_ITEM )))
  395.             return( FALSE );
  396.  
  397.             AddTail( (struct List *)&gad->g_Scelte, (struct Node *)gs );
  398.             gs->gs_Node.ln_Name = gs->gs_Testo;
  399.  
  400.             strcpy( gs->gs_Testo, *labels++ );
  401.         }
  402.         }
  403.         break;
  404.  
  405.     case    MX_KIND:
  406.         labels = (UBYTE **)GetTagData( GTMX_Labels, NULL, from->en_Tags );
  407.  
  408.         // count the labels
  409.         cnt = 0;
  410.         while( labels[ cnt ] )
  411.         cnt++;
  412.  
  413.         gad->g_NumScelte = cnt;
  414.  
  415.         for( cnt2 = 0; cnt2 < gad->g_NumScelte; cnt2++ ) {
  416.         if(!( gs = ( *IE->Functions->AllocObject )( IE_ITEM )))
  417.             return( FALSE );
  418.  
  419.         AddTail( (struct List *)&gad->g_Scelte, (struct Node *)gs );
  420.         gs->gs_Node.ln_Name = gs->gs_Testo;
  421.  
  422.         strcpy( gs->gs_Testo, *labels++ );
  423.         }
  424.  
  425.         if ( GTX_TagInArray( GTMX_Spacing, from->en_Tags ))
  426.         ((struct MK)( gad->g_Data )).Spc = GetTagData( GTMX_Spacing, 0, from->en_Tags );
  427.         else
  428.         ((struct MK)(gad->g_Data)).Spc = 1;
  429.         if ( GTX_TagInArray( GTMX_Active, from->en_Tags ))
  430.         ((struct MK)( gad->g_Data )).Act = GetTagData( GTMX_Active, 0, from->en_Tags );
  431.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  432.         gad->g_Tags |= 2;
  433.         break;
  434.  
  435.     case    PALETTE_KIND:
  436.         ((struct PK)( gad->g_Data)).Depth = GetTagData( GTPA_Depth, 1, from->en_Tags );
  437.         if ( GTX_TagInArray( GTPA_IndicatorWidth, from->en_Tags ))
  438.         ((struct PK)( gad->g_Data )).IW = GetTagData( GTPA_IndicatorWidth, NULL, from->en_Tags );
  439.         if ( GTX_TagInArray( GTPA_IndicatorHeight, from->en_Tags ))
  440.         ((struct PK)( gad->g_Data )).IH = GetTagData( GTPA_IndicatorHeight, NULL, from->en_Tags );
  441.         if ( GTX_TagInArray( GTPA_Color, from->en_Tags ))
  442.         ((struct PK)( gad->g_Data )).Color = GetTagData( GTPA_Color, 1, from->en_Tags );
  443.         else
  444.         ((struct PK)( gad->g_Data )).Color = 1;
  445.         if ( GTX_TagInArray( GTPA_ColorOffset, from->en_Tags ))
  446.         ((struct PK)( gad->g_Data)).ColOff = GetTagData( GTPA_ColorOffset, 0, from->en_Tags );
  447.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  448.         gad->g_Tags |= 2;
  449.         break;
  450.  
  451.     case    SCROLLER_KIND:
  452.         if ( GTX_TagInArray( GTSC_Top, from->en_Tags ))
  453.         ((struct SK)( gad->g_Data)).Top = GetTagData( GTSC_Top, NULL, from->en_Tags );
  454.         if ( GTX_TagInArray( GTSC_Total, from->en_Tags ))
  455.         ((struct SK)( gad->g_Data)).Tot = GetTagData( GTSC_Total, NULL, from->en_Tags );
  456.         if ( GTX_TagInArray( GTSC_Visible, from->en_Tags ))
  457.         ((struct SK)( gad->g_Data)).Vis = GetTagData( GTSC_Visible, NULL, from->en_Tags );
  458.         else
  459.         ((struct SK)(gad->g_Data)).Vis = 2;
  460.         if ( GTX_TagInArray( GTSC_Arrows, from->en_Tags ))
  461.         ((struct SK)( gad->g_Data)).Arr = GetTagData( GTSC_Arrows, 0, from->en_Tags );
  462.         if ( GTX_TagInArray( PGA_Freedom, from->en_Tags ))
  463.         ((struct SK)( gad->g_Data)).Free = 1;
  464.         if ( GTX_TagInArray( GA_Immediate, from->en_Tags ))
  465.         gad->g_Tags |= 8;
  466.         if ( GTX_TagInArray( GA_RelVerify, from->en_Tags ))
  467.         gad->g_Tags |= 4;
  468.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  469.         gad->g_Tags |= 2;
  470.         break;
  471.  
  472.     case    SLIDER_KIND:
  473.         if ( GTX_TagInArray( GTSL_Min, from->en_Tags ))
  474.         ((struct SlK)( gad->g_Data)).Min = GetTagData( GTSL_Min, NULL, from->en_Tags );
  475.         if ( GTX_TagInArray( GTSL_Max, from->en_Tags ))
  476.         ((struct SlK)( gad->g_Data)).Max = GetTagData( GTSL_Max, NULL, from->en_Tags );
  477.         else
  478.         ((struct SlK)( gad->g_Data)).Max = 15;
  479.         if ( GTX_TagInArray( GTSL_Level, from->en_Tags ))
  480.         ((struct SlK)( gad->g_Data)).Level = GetTagData( GTSL_Level, NULL, from->en_Tags );
  481.         if ( GTX_TagInArray( GTSL_MaxLevelLen, from->en_Tags ))
  482.         ((struct SlK)( gad->g_Data)).MLL = GetTagData( GTSL_MaxLevelLen, NULL, from->en_Tags );
  483.         else
  484.         ((struct SlK)( gad->g_Data)).MLL = 2;
  485.  
  486.         if ( GTX_TagInArray( GTSL_LevelFormat, from->en_Tags ))
  487.         strcpy( ((struct SlK)( gad->g_Data)).Format, ( UBYTE * )GetTagData( GTSL_LevelFormat, 0, from->en_Tags ));
  488.         else
  489.         strcpy( ((struct SlK)( gad->g_Data)).Format, "%ld" );
  490.  
  491.         if ( GTX_TagInArray( GTSL_LevelPlace, from->en_Tags )) {
  492.         cnt = GetTagData( GTSL_LevelPlace, NULL, from->en_Tags );
  493.  
  494.         cnt2 = 0;
  495.         while( gadget_flags[ cnt2 ] != cnt )
  496.             cnt2++;
  497.  
  498.         ((struct SlK)( gad->g_Data)).LevPlc = cnt2;
  499.         }
  500.         if ( GTX_TagInArray( PGA_Freedom, from->en_Tags ))
  501.         ((struct SlK)( gad->g_Data)).Free = 1;
  502.  
  503.         if ( GTX_TagInArray( GA_Immediate, from->en_Tags ))
  504.         gad->g_Tags |= 8;
  505.         if ( GTX_TagInArray( GA_RelVerify, from->en_Tags ))
  506.         gad->g_Tags |= 4;
  507.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  508.         gad->g_Tags |= 2;
  509.         break;
  510.  
  511.     case    STRING_KIND:
  512.         if ( GTX_TagInArray( GA_TabCycle, from->en_Tags ))
  513.         gad->g_Tags |= 8;
  514.         if ( GTX_TagInArray( STRINGA_ExitHelp, from->en_Tags ))
  515.         gad->g_Tags |= 0x10;
  516.         if ( ptr = ( UBYTE * )GetTagData( GTST_String, NULL, from->en_Tags )) {
  517.         strcpy( gad->g_ExtraMem, ptr );
  518.         }
  519.         ((struct StK)( gad->g_Data)).MaxC = GetTagData( GTST_MaxChars, 64, from->en_Tags );
  520.  
  521.         if ( cnt = GetTagData( STRINGA_Justification, 0l, from->en_Tags )) {
  522.         cnt2 = 0;
  523.         while( stringjusts[ cnt2 ] != cnt )
  524.             cnt2++;
  525.         ((struct StK)( gad->g_Data )).Just = cnt2;
  526.         }
  527.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  528.         gad->g_Tags |= 2;
  529.         break;
  530.  
  531.     case    NUMBER_KIND:
  532.         if ( GTX_TagInArray( GTNM_Number, from->en_Tags ))
  533.         ((struct NK)( gad->g_Data )).Num = GetTagData( GTNM_Number, 0, from->en_Tags );
  534.         if ( GTX_TagInArray( GTNM_Border, from->en_Tags ))
  535.         gad->g_Tags |= 2;
  536.         ((struct NK)(gad->g_Data)).MNL = 10;
  537.         ((struct NK)(gad->g_Data)).FPen = -1;
  538.         ((struct NK)(gad->g_Data)).BPen = -1;
  539.         strcpy( ((struct NK)(gad->g_Data)).Format, "%ld" );
  540.         break;
  541.  
  542.     case    TEXT_KIND:
  543.         strcpy( gad->g_ExtraMem, ( UBYTE * )GetTagData( GTTX_Text, NULL, from->en_Tags ));
  544.  
  545.         ((struct TK)(gad->g_Data)).FPen = -1;
  546.         ((struct TK)(gad->g_Data)).BPen = -1;
  547.  
  548.         if ( GTX_TagInArray( GTTX_Border, from->en_Tags ))
  549.         gad->g_Tags |= 4;
  550.         if ( GTX_TagInArray( GTTX_CopyText, from->en_Tags ))
  551.         gad->g_Tags |= 2;
  552.         break;
  553.  
  554.     }
  555.  
  556.     if( GTX_TagInArray( GT_Underscore, from->en_Tags ))
  557.     gad->g_Tags |= 1;
  558.  
  559.     // let's get the activation key
  560.     if( gad->g_Tags & 1 ) {
  561.     ptr = gad->g_Titolo;
  562.     do{
  563.         ch = *ptr++;
  564.     } while(( ch != '_' ) && ( ch != '\0' ));
  565.     if( ch ) {
  566.         gad->g_Key = *ptr;
  567.         wnd->wi_NumKeys += 1;
  568.     }
  569.     }
  570.  
  571.     wnd->wi_GadTypes[ gad->g_Kind - 1 ] += 1;
  572.     wnd->wi_NumGads += 1;
  573.  
  574.     return( TRUE );
  575. }
  576. ///
  577. /// Menus
  578. BOOL ConvertMenus( struct IE_Data *IE, struct WindowInfo *wnd, struct ExtMenuList *from )
  579. {
  580.     struct MenuTitle   *title;
  581.     struct _MenuItem   *item;
  582.     struct MenuSub     *sub;
  583.     struct ExtNewMenu  *from_m, *from_i, *from_s;
  584.  
  585.     for( from_m = from->ml_First; from_m->em_Next; from_m = from_m->em_Next ) {
  586.     if( title = ( *IE->Functions->AllocObject )( IE_MENUTITLE )) {
  587.  
  588.         AddTail( (struct List *)&wnd->wi_Menus, (struct Node *)title );
  589.         title->mt_Node.ln_Name = title->mt_Text;
  590.  
  591.         wnd->wi_NumMenus += 1;
  592.  
  593.         NewList( &title->mt_Items );
  594.  
  595.         strcpy( title->mt_Text, from_m->em_MenuTitle );
  596.         strcpy( title->mt_Label, from_m->em_MenuLabel );
  597.  
  598.         for( from_i = from_m->em_Items->ml_First; from_i->em_Next; from_i = from_i->em_Next ) {
  599.  
  600.         if( item = ( *IE->Functions->AllocObject )( IE_MENUITEM )) {
  601.  
  602.             AddTail( (struct List *)&title->mt_Items, (struct Node *)item );
  603.             item->min_Node.ln_Name = item->min_Text;
  604.             NewList( &item->min_Subs );
  605.  
  606.             title->mt_NumItems += 1;
  607.  
  608.             if( from_i->em_NewMenu.nm_Label = NM_BARLABEL )
  609.             item->min_Node.ln_Name = Bar_txt;
  610.  
  611.             strcpy( item->min_Text, from_i->em_MenuTitle );
  612.             strcpy( item->min_CommKey, from_i->em_CommKey );
  613.             strcpy( item->min_Label, from_i->em_MenuLabel );
  614.  
  615.             item->min_MutualExclude = from_i->em_NewMenu.nm_MutualExclude;
  616.  
  617.             for( from_s = from_i->em_Items->ml_First; from_s->em_Next; from_s = from_s->em_Next ) {
  618.  
  619.             if( sub = ( *IE->Functions->AllocObject )( IE_MENUSUB )) {
  620.  
  621.                 AddTail( (struct List *)&item->min_Subs, (struct Node *)sub );
  622.                 sub->msn_Node.ln_Name = sub->msn_Text;
  623.  
  624.                 item->min_NumSubs += 1;
  625.  
  626.                 if( from_s->em_NewMenu.nm_Label = NM_BARLABEL )
  627.                 sub->msn_Node.ln_Name = Bar_txt;
  628.  
  629.                 strcpy( sub->msn_Text, from_s->em_MenuTitle );
  630.                 strcpy( sub->msn_CommKey, from_s->em_CommKey );
  631.                 strcpy( sub->msn_Label, from_s->em_MenuLabel );
  632.  
  633.                 sub->msn_MutualExclude = from_s->em_NewMenu.nm_MutualExclude;
  634.  
  635.             } else {
  636.                 return( FALSE );
  637.             }
  638.             }
  639.  
  640.         } else {
  641.             return( FALSE );
  642.         }
  643.         }
  644.  
  645.     } else {
  646.         return( FALSE );
  647.     }
  648.     }
  649.  
  650.     return( TRUE );
  651. }
  652. ///
  653. /// Screen
  654. ULONG ConvertScr( struct IE_Data *IE, GUIDATA *GuiInfo )
  655. {
  656.     IE->ScreenData->Tags[ SCRWIDTH    ] = GuiInfo->gui_Width;
  657.     IE->ScreenData->Tags[ SCRHEIGHT   ] = GuiInfo->gui_Height;
  658.     IE->ScreenData->Tags[ SCRDEPTH    ] = GuiInfo->gui_Depth;
  659.     IE->ScreenData->Tags[ SCRID       ] = GuiInfo->gui_DisplayID;
  660.     IE->ScreenData->Tags[ SCROVERSCAN ] = GuiInfo->gui_Overscan;
  661.     IE->ScreenData->Tags[ SCRAUTOSCROLL ] = ( GuiInfo->gui_Flags0 & GU0_AUTOSCROLL ) ? TRUE : FALSE;
  662.  
  663.     IE->ScreenData->NewFont.ta_YSize = GuiInfo->gui_Font.ta_YSize;
  664.     IE->ScreenData->NewFont.ta_Flags = GuiInfo->gui_Font.ta_Flags;
  665.     IE->ScreenData->NewFont.ta_Style = GuiInfo->gui_Font.ta_Style;
  666.     strcpy( IE->ScreenData->NewFont.ta_Name, GuiInfo->gui_Font.ta_Name );
  667.  
  668.     ( *IE->Functions->AddFont )( &GuiInfo->gui_Font );
  669.  
  670.     strcpy( IE->ScreenData->Title, GuiInfo->gui_ScreenTitle );
  671.  
  672.     IE->ScreenData->St_Left = GuiInfo->gui_Left;
  673.     IE->ScreenData->St_Top  = GuiInfo->gui_Top;
  674.  
  675.     if( GuiInfo->gui_Flags0 & GU0_PUBLIC )
  676.     IE->ScreenData->Type = PUBLICSCREEN;
  677.     else
  678.     IE->ScreenData->Type = CUSTOMSCREEN;
  679.  
  680.     memcpy( IE->ScreenData->DriPens, GuiInfo->gui_DriPens, 20 );
  681.     IE->ScreenData->DriPens[10] = GuiInfo->gui_MoreDriPens[0];
  682.     IE->ScreenData->DriPens[11] = GuiInfo->gui_MoreDriPens[1];
  683.  
  684.     #ifdef DEBUG
  685.     Printf( "ConvertScr() OK\n" );
  686.     #endif
  687.  
  688.     return( ConvertColors( IE, 1 << IE->ScreenData->Tags[ SCRDEPTH ], GuiInfo ));
  689. }
  690.  
  691. ULONG ConvertColors( struct IE_Data *IE, UWORD num, GUIDATA *GuiInfo )
  692. {
  693.     UWORD               c;
  694.     struct ColorSpec   *col;
  695.     ULONG               ret = LOADER_OK;
  696.  
  697.     if( GuiInfo->gui_Colors[0].ColorIndex == -1 )
  698.     return( LOADER_OK );
  699.  
  700.     if( IE->colortable )           // make sure to release it
  701.     FreeVec( IE->colortable );
  702.  
  703.     if( SysBase->LibNode.lib_Version >= 39 ) {  // Kick 3.0
  704.  
  705.     ULONG  *ptr;
  706.     if( ptr = IE->colortable = AllocVec(( num * 12 ) + 8, 0L )) {
  707.  
  708.         *ptr++ = num << 16;
  709.  
  710.         for( c = 0; c < num; c++ ) {
  711.  
  712.         col = &GuiInfo->gui_Colors[ c ];
  713.  
  714.         if( col->ColorIndex != -1 ) {
  715.             ULONG c3;
  716.  
  717.             // Now we MUST scale the color values from
  718.             // 4 bit per gun to 32 bit per gun
  719.  
  720.             c3 = (col->Red << 4) | col->Red;
  721.             c3 |= c3 << 8;
  722.             *ptr++ = c3 | ( c3 << 16 );
  723.  
  724.             c3 = (col->Green << 4) | col->Green;
  725.             c3 |= c3 << 8;
  726.             *ptr++ = c3 | ( c3 << 16 );
  727.  
  728.             c3 = (col->Blue << 4) | col->Blue;
  729.             c3 |= c3 << 8;
  730.             *ptr++ = c3 | ( c3 << 16 );
  731.  
  732.         } else {
  733.             c = num;
  734.         }
  735.  
  736.         }
  737.         *ptr = NULL;
  738.  
  739.     } else {
  740.         ret = LOADER_NOMEMORY;
  741.     }
  742.     } else {                             // Kick 2.0
  743.  
  744.     UWORD *ptr2;
  745.     if( ptr2 = IE->colortable = AllocVec( num + num + 2, 0L )) {
  746.  
  747.         *ptr2++ = num;
  748.  
  749.         for( c = 0; c < num; c ++ ) {
  750.  
  751.         col = &GuiInfo->gui_Colors[ c ];
  752.  
  753.         *ptr2++ = (col->Red << 8) | (col->Green << 4) | col->Blue;
  754.         }
  755.  
  756.     } else {
  757.         ret = LOADER_NOMEMORY;
  758.     }
  759.     }
  760.  
  761.     #ifdef DEBUG
  762.     Printf( "ConvertColors() OK\n" );
  763.     #endif
  764.  
  765.     return( ret );
  766. }
  767. ///
  768.  
  769. // Main routines
  770. /// LoadGUI
  771. ULONG LoadGUI( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  772. {
  773.     APTR                    Chain;
  774.     ULONG                   ret;
  775.     struct WindowList       Windows;
  776.     GUIDATA                 GuiInfo;
  777.     struct ProjectWindow   *wnd;
  778.  
  779.     if(!( Chain = GetMemoryChain( 4096L )))
  780.     return( LOADER_NOMEMORY );
  781.  
  782.     NewList( &Windows );
  783.  
  784.     if( ret = GTX_LoadGUI( Chain, Filename,
  785.                RG_WindowList, &Windows,
  786.                RG_GUI, &GuiInfo,
  787.                TAG_END )) {
  788.  
  789.     switch( ret ) {
  790.         case ERROR_NOMEM:
  791.         ret = LOADER_NOMEMORY;
  792.         break;
  793.  
  794.         case ERROR_OPEN:
  795.         case ERROR_READ:
  796.         case ERROR_WRITE:
  797.         case ERROR_PARSE:
  798.         case ERROR_PACKER:
  799.         case ERROR_PPLIB:
  800.         ret = LOADER_IOERR;
  801.         break;
  802.  
  803.         case ERROR_NOTGUIFILE:
  804.         ret = LOADER_UNKNOWN;
  805.         break;
  806.     }
  807.  
  808.     } else {
  809.  
  810.     for( wnd = Windows.wl_First; wnd->pw_Next; wnd = wnd->pw_Next ) {
  811.  
  812.         if(!( IE->win_info = ConvertWin( IE, wnd ))) {
  813.         ret = LOADER_NOMEMORY;
  814.         goto done;
  815.         }
  816.     }
  817.  
  818.     ret = ConvertScr( IE, &GuiInfo );
  819.  
  820. done:
  821.  
  822.     GTX_FreeWindows( Chain, &Windows );
  823.     }
  824.  
  825.     FreeMemoryChain( Chain, TRUE );
  826.  
  827.     return( ret );
  828. }
  829. ///
  830.  
  831. // These routines are not supported by this module since they need
  832. // some *private* functions of gadtoolsbox.library... But if you can
  833. // implement them, well, you'd do a great thing! ;-)
  834. /// LoadWindows
  835. ULONG LoadWindows( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  836. {
  837.     return( LOADER_NOTSUPPORTED );
  838. }
  839. ///
  840. /// LoadGadgets
  841. ULONG LoadGadgets( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  842. {
  843.     return( LOADER_NOTSUPPORTED );
  844. }
  845. ///
  846. /// LoadScreen
  847. ULONG LoadScreen( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  848. {
  849.     return( LOADER_NOTSUPPORTED );
  850. }
  851. ///
  852.  
  853.